package logic

import (
	"context"
	"shopping/shoprpc/shoprpc"

	"shopping/api/internal/svc"
	"shopping/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProductLikeLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewProductLikeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductLikeLogic {
	return &ProductLikeLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ProductLikeLogic) ProductLike(req *types.ProductLikeRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	like, err := l.svcCtx.ShopRpc.ProductLike(l.ctx, &shoprpc.ProductLikeRequest{ProductId: req.ProductId})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    "500",
			Data:    nil,
		}, nil
	}

	return &types.Response{
		Message: "收藏成功",
		Code:    "200",
		Data:    like,
	}, nil
}
